#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 50.py
# @time: 2022/11/18
# @software: VS Code

class Solution:
    def myPow(self, x: float, n: int) -> float:
        result = 0.0
        if x != 0:
            result = 1.0
            if n != 0:
                y = x if n > 0 else 1 / x
                n = n if n > 0 else -n
                # 快速幂循环版
                while n > 0:
                    # 每次检查n的二进制最后是不是1
                    # 为1时，需要将对应x^(2^k)计入结果
                    if n & 1:
                        result *= y
                    # y是x^(2^k)
                    y *= y
                    n //= 2
        return result


if __name__ == "__main__":
    solu = Solution()
    result = solu.myPow(2,10)
    print(result)
